/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */




function Chtml(data) {

    return   unescape(data);



}

function Ahtml(data) {

    return  escape(data);

}

function updateAttr(name, val) {

    var data = "";

    if (val != null && val != undefined && val != "")
    {
        data = name + "=" + '"' + val + '"';

    }

    return data;

}

function getValueDataByValue(myclass, type) {
    var returnData = [];

    myclass = unescape(myclass);

    var data = myclass.split(";");

    if (data[type] != null) {
        return data[type].split("__");

    }

}

function getValueData(myclass, type) {

    var returnData = "";
    var v = unescape($("." + myclass).val());
    var data = v.split(";");

    if (data[type] != null) {

        returnData = data[type].split("__");
    }



    return   returnData;

}

function getAttrValue(v, without) {



    v = unescape(v);
    var data = v.split(";");
    var returnData = "";

    if (data[1] != null && data[1] != null) {
        var names = data[0].split("__");
        var values = data[1].split("__");



        for (var i = 0; i < names.length; i++) {

            var withoutarr = without.split(",");

            if (without == null || withoutarr.indexOf(names[i]) < 0) {
                if (values[i] != null && values[i] != undefined && values[i] != "")
                {
                    returnData += " " + names[i] + "=\"" + values[i] + "\" ";
                }
            }









        }


    }
    return returnData;
}

function getoptions(arrOptionsvalue, arrOptionstext, removeValue) {

    var returnData = "";

    for (r = 0; r < removeValue.length; r++) {
        if (removeValue[r] != "") {
            var idx = arrOptionsvalue.indexOf(removeValue[r]);

            if (idx != -1) {
                arrOptionsvalue.splice(idx, 1);
            }

            var idxt = arrOptionstext.indexOf(removeValue[r]);
            if (idxt != -1) {
                arrOptionstext.splice(idxt, 1);
            }
        }
    }



    for (i = 0; i < arrOptionsvalue.length; i++) {

        if (arrOptionstext[i] != "") {

            returnData += "<option value='" + arrOptionsvalue[i] + "'>" + arrOptionstext[i] + "</option>";

        }

    }

    return  returnData;
}

function createIntput(Value, Class, style, type) {


    var td = document.createElement('td');
    td.style.fontSize = '10pt';

    var myinput = document.createElement('input');
    myinput.setAttribute('class', Class);


    if (Value != null && Value != undefined && Value != "undefined") {
        myinput.setAttribute('value', Value);


    }

    if (type != null && type != undefined && type != "undefined") {
        myinput.setAttribute('type', type);
        if (Value == "checked") {
            myinput.setAttribute('checked', 'checked');

        }






    }


    myinput.setAttribute('style', style);

    td.appendChild(myinput);
    return td

}

function createLabel(Value, colspan) {

    var td = document.createElement('td');
    if (colspan != null) {


        td.setAttribute('colspan', colspan);
    }




    td.style.fontSize = '10pt';
    mxUtils.write(td, Value);
    return td;

}

function createSelect(selected, Class, style, arrOptionsValue, arrOptionsText) {


    var td = document.createElement('td');
    td.style.fontSize = '10pt';

    var myselect = document.createElement('select');

    myselect.setAttribute('class', Class);
    myselect.setAttribute('style', style);

    for (i = 0; i < arrOptionsValue.length; i++) {

        if ($.trim(arrOptionsValue[i]) != "") {


            if (arrOptionsValue[i] != null && $.trim(arrOptionsValue[i]) != "null") {


                var Option = document.createElement('option');
                Option.setAttribute('value', arrOptionsValue[i]);

                if (selected == arrOptionsValue[i]) {

                    Option.setAttribute('selected', 'selected');

                }



                mxUtils.write(Option, arrOptionsText[i]);
                myselect.appendChild(Option);

            }
        }


    }





    td.appendChild(myselect);
    return td

}

function createItem(item) {


    var td = document.createElement('td');
    td.style.fontSize = '10pt';

    td.appendChild(item);
    return td

}

function createItem(title, style, Class) {

    var table = document.createElement('table');
    table.style.width = '100%';
    table.style.height = '100%';
    var tbody = document.createElement('tbody');
    row = document.createElement('tr');
    td = document.createElement('td');
    td.style.fontSize = '12pt';
    td.style.color = "blue";

    td.setAttribute('class', Class);
    td.setAttribute('style', style);

    mxUtils.write(td, title);
    row.appendChild(td);
    tbody.appendChild(row);


    tbody.appendChild(row);


    table.appendChild(tbody);
    return table;

}

function getSesstion(name, callback) {
    $.ajax({
        type: 'GET',
        url: "ajax/getSesstion.jsp?type=" + name,
        success: callback
    });
}

function clearSesstion(name) {

    $.get("ajax/createSession.jsp?type=perData" + name, function() {

    });
}

function getAjax(name, callback) {
    $.ajax({
        type: 'GET',
        url: 'someURL',
        success: callback
    });
}

function setSesstion(name, myvalue, callback) {
    if (callback == null) {

        $.post("ajax/createSession.jsp", {data: myvalue, type: name}, function() {
        });
    } else {

        $.post("ajax/createSession.jsp", {data: myvalue, type: name}, callback);
    }



}

function returnInputField(name, value) {

    var mytext = name.replaceAll(" ", "_");
    setSesstion(mytext, value);
    return "<input name='" + name + "' class='" + name + "' type='hidden' value='" + escape(value) + "' />";

}

function getEdges(id, graph) {
    var returdata = "";
    var cells = graph.getChildCells(graph.getDefaultParent(), true, true);
    for (var i = 0; i < cells.length; i++) {
        var v = cells[i].getValue();
        if (cells[i].isEdge()) {
            if (cells[i].source.getId() == id) {
                returdata += cells[i].target.getValue() + "__";
            }
        }
    }
    return returdata;
}

function getCells(graph) {
    var returdata = "";
    var cells = graph.getChildCells(graph.getDefaultParent(), true, true);
    for (var i = 0; i < cells.length; i++) {
        if (!cells[i].isEdge()) {
            returdata += cells[i].getValue() + "__";
        }
    }

    return returdata;
}




function ISCell(graph, id) {
    var returdata = false;

    var cells = graph.getChildCells(graph.getDefaultParent(), true, true);



    for (var i = 0; i < cells.length; i++) {
        if (!cells[i].isEdge()) {


            if (cells[i].getId() == id) {
                returdata = true;
            }
        }
    }

    return returdata;
}




function getBCells(graph) {
    var returdata = [];
    var cells = graph.getChildCells(graph.getDefaultParent(), true, true);


    for (var i = 0; i < cells.length; i++) {
        if (cells[i].isVertex()) {
            if (cells[i] != null) {

                returdata [i] = cells[i];
            }

        }
    }

    return returdata;
}


















function getBEdge(graph) {
    var returdata = [];
    var cells = graph.getChildCells(graph.getDefaultParent(), true, true);


    for (var i = 0; i < cells.length; i++) {
        if (cells[i].isEdge()) {
            returdata [i] = cells[i];
        }
    }

    return returdata;
}


function getEdgesForCell(id) {

    var returnData = "";
    var cells = graph.getChildCells(graph.getDefaultParent(), true, true);
    for (var i = 0; i < cells.length; i++) {
        var v = cells[i].getValue();


        if (cells[i].isEdge()) {

            if (cells[i].source.getId() == id) {

                returnData += cells[i].target.getValue() + "__";


            }


        }
    }

    return returnData;
}



















function showXmlFile() {

    $.get("ajax/creatXmlfile.jsp", function() {

        window.open(
                'data.xml',
                '_blank' // <- This is what makes it open in a new window.
                );


    });



}

function getEdges(graph) {
    var returdata = "";
    var cells = graph.getChildCells(graph.getDefaultParent(), true, true);
    for (var i = 0; i < cells.length; i++) {
        if (cells[i].isEdge()) {
            returdata += cells[i].source.getValue() + ";" + cells[i].target.getValue() + ";" + "__";
        }
    }

    return returdata;
}


Array.prototype.remove = function() {
    var what, a = arguments, L = a.length, ax;
    while (L && this.length) {
        what = a[--L];
        while ((ax = this.indexOf(what)) != -1) {
            this.splice(ax, 1);
        }
    }
    return this;
}

